package com.realbrand.net.realbrandpay.ui.activity.wallet.order;

import com.realbrand.net.realbrandpay.api.HTTPAPI;
import com.realbrand.net.realbrandpay.bean.OrderBean;
import com.realbrand.net.realbrandpay.inter.IGetAllOrdersInfo;
import com.realbrand.net.realbrandpay.inter.IGetOrdersInfo;
import com.realbrand.net.realbrandpay.untils.HttpRequest;
import com.realbrand.net.realbrandpay.zxing.util.L;

import okhttp3.RequestBody;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/5/18.
 */

public class ModelOrder {
    //获取部分订单信息
    public static void getOrderInfo(String prama, final IModelOrder<OrderBean> iModelOrder) {
        RequestBody body = RequestBody.create(HTTPAPI.JSON, prama);
        IGetOrdersInfo iGetOrdersInfo = HttpRequest.request_BASE_URL_VERSION(IGetOrdersInfo.class, HTTPAPI.BASE_TEXTURL);
        iGetOrdersInfo.getOrderInfo(body)
                .subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OrderBean>() {
                    @Override
                    public void onCompleted() {
                        iModelOrder.onComplete();
                    }

                    @Override
                    public void onError(Throwable e) {
                        L.d(L.TAG, "订单信息异常原因"+e.toString());
                        iModelOrder.onFail(e.toString());
                    }

                    @Override
                    public void onNext(OrderBean orderBean) {
                        iModelOrder.onSuccess(orderBean);
                    }
                });
    }
    //获取全部订单信息
    public static void getAllOrderInfo(String prama, final IModelOrder<OrderBean> iModelOrder) {
        RequestBody body = RequestBody.create(HTTPAPI.JSON, prama);
        IGetAllOrdersInfo iGetAllOrdersInfo = HttpRequest.request_BASE_URL_VERSION(IGetAllOrdersInfo.class, HTTPAPI.BASE_TEXTURL);
        iGetAllOrdersInfo.getAllOrderInfo(body)
                .subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<OrderBean>() {
                    @Override
                    public void onCompleted() {
                        iModelOrder.onComplete();
                    }

                    @Override
                    public void onError(Throwable e) {
                        L.d(L.TAG, "订单信息异常原因"+e.toString());
                        iModelOrder.onFail(e.toString());
                    }

                    @Override
                    public void onNext(OrderBean orderBean) {
                        iModelOrder.onSuccess(orderBean);
                    }
                });
    }
}
